package com.jkc.xh.adapters;

import android.view.View;
import android.view.ViewGroup;

import com.jkc.xh.R;
import com.jkc.xh.adapters.core.BaseRecyclerAdapter;
import com.jkc.xh.adapters.viewholder.AutoSoldPartItemView;
import com.jkc.xh.adapters.viewholder.AutoSoldPartItemView_;
import com.jkc.xh.models.HoldOneModel;

/**
 * Created by macintosh on 15/11/17.
 */
public class TradeAutoSoldPartAdapter extends BaseRecyclerAdapter<HoldOneModel, AutoSoldPartItemView> implements BaseRecyclerAdapter.OnItemClickListener {
    private View currentView = null;

    public TradeAutoSoldPartAdapter(OnViewClickListener listener){
        setListener(listener);
    }

    @Override
    protected void onBindView(AutoSoldPartItemView itemView, HoldOneModel orderModel, int position) {
        itemView.bind(orderModel);
    }

    @Override
    protected AutoSoldPartItemView onCreateItemView(ViewGroup parent, int viewType) {
        return AutoSoldPartItemView_.build(parent.getContext());
    }

    @Override
    public void onItemClick(View view, Object object, int position) {
        if (currentView == null) {
            currentView = view;
        } else {
            if (currentView == view) {
                ((AutoSoldPartItemView) currentView).disableMoreOption();
                currentView = null;
                return;
            }
            ((AutoSoldPartItemView) currentView).disableMoreOption();
            currentView = view;
        }
        ((AutoSoldPartItemView) currentView).showMoreOption();
    }

    public void clearCurrentMoreView() {
        if (currentView != null) {
            ((AutoSoldPartItemView) currentView).disableMoreOption();
            currentView = null;
        }
    }

    public void setListener(OnViewClickListener listener) {
        addOnViewClickListener(R.id.btnSoldPart, listener);
    }
}
